﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using DevExpress.XtraGrid;
using DevExpress.XtraCharts;
using System.Collections;
using Lamex.Library.CommonClass;
using Lamex.Interface;
using Lamex.Common;

namespace Lamex.mEfficiency.UI
{
    public partial class frmEFF_Efficiency_Analyse : frmBaseChild
    {
        string strD1, strD2;
        string strLevel, strFilter, strSql;
        DataTable dt;

        public frmEFF_Efficiency_Analyse()
        {
            InitializeComponent();
        }

        private void frmEFF_Inside_Analyse_Load(object sender, EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理

            doConditionDriverLevel();

            string CurUser = Lamex.Common.Loginer.CurrentUser.Account;
            switch (CurUser)
            {
                case "Rocky He":
                    dteStart.EditValue = "2020/6/15";
                    dteEnd.EditValue = "2020/6/19";
                    break;
                default:
                    dteStart.DateTime = DateTime.Now;
                    break;
            }

            //dteStart.DateTime = DateTime.Now;

            gridView1.OptionsBehavior.Editable = false;
            gridView1.OptionsView.ColumnAutoWidth = true;
        }

        //【总原则】
        //【有入仓数，必须要有人工工时发生】——检查漏录人工工时逻辑，即入仓天vs人工天
        //【有人工工时，不一定需要有入仓数】——效率计算原则，即总标准工时vs总人工工时
        private void sbtnView_Click(object sender, EventArgs e)
        {
            doClearViewAndChartData();

            if (string.IsNullOrEmpty(cbxItems_Child.Text) || string.IsNullOrEmpty(dteStart.Text) || string.IsNullOrEmpty(dteEnd.Text))
            {
                DevExpress.XtraEditors.XtraMessageBox.Show("子项及起止日期不允许为空", "提示", MessageBoxButtons.OK);
                return;
            }

            getFilterDate();//获取起止时间段
            getLevelString();//获取分析层级

            getFilterString();//获取子项查询条件


            //确定是否继续，检查是否漏人工工时后的并确定处理方式
            if (isContinueAferCheckLaborTime(strD1,strD2) == false)
            {
                this.Text = "排产趋势";
                return;
            }

            //因同一包装体包含多个部件，不同部件有可能在不同分厂（或/和站点、或/和工序）生产，
            //即每一个包装体其包含工时，可能跨分厂、跨站点、跨工序
            //【所以产量均按件数（部件）统计，而不按包数统计】

            //因处理不了SYSTEM.DBNull报错，用ISNULL(引用数据列,强制转换值)，
            //即【ISNULL(工时,0)】表示将NULL值强制转换成0值

            strSql = "";
            dt = null;

            if (rbtnSummarize.Checked == true)
            {
                getSQL_Summrize();
            }
            else
            {
                //待人工工时维护系统上线后再启用
                getSQL_Trending();
            }

            //刷新图表
            if (strSql != "")
            {
                dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                if (dt.Rows.Count > 0)
                {
                    setData_GridView(dt);
                    TotalSum();//统计求和

                    if (rbtnSummarize.Checked == true)
                    {
                        setData_ChartControl(dt, chartControl1, strLevel, "部件数量");
                        setData_ChartControl(dt, chartControl2, strLevel, "效率");
                    }
                    else
                    {
                        setData_ChartControl(dt, chartControl1, "扫描日期", "部件数量");
                        setData_ChartControl(dt, chartControl2, "扫描日期", "效率");
                    }

                    //设置数据显示形式(Percent:百分比,Currency:货币类型，数据前添加￥,Scientific:科学计数法)
                    //chartControl2.Series[0].Label.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                    //chartControl2.Series[0].Label.TextPattern = "{V}";
                    //chartControl2.Series[0].Label.TextPattern = "{A}: {V:F1}";
                    chartControl2.Series[0].Label.TextPattern = "{A}: {VP:P2}";

                    XYDiagram diagram = ((XYDiagram)chartControl2.Diagram);
                    diagram.AxisY.Label.TextPattern = "{VP}";



                    //数据是否保留小数(0：不保留小数位，1保留一位小数，2保留两位小数)
                    //chartControl2.Series[0].Label.PointOptions.ValueNumericOptions.Precision = 1;

                    //显示
                    //chartControl2.Series[0].LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
                }
            }
        }

        //获取起止时间段
        private void getFilterDate()
        {
            strD1 = dteStart.Text.ToString();

            if (dteEnd.Text == "")
            {
                strD2 = strD1;
            }
            else
            {
                strD2 = dteEnd.Text.ToString();
            }
        }
        
        //获取分析层级字符串
        private string getLevelString()
        {
            strLevel = "";
            if (rbtnFactory.Checked == true)
            {
                strLevel = "分厂";
            }
            else if (rbtnStation.Checked == true)
            {
                strLevel = "工作站";
            }
            return strLevel;
        }

        //获取分析层级字符串
        private string getFilterString()
        {
            strFilter = "";
            if (strLevel == "分厂")
            {
                if (cbxItems_Child.Text == "全部")
                {
                    strFilter = "1=1";
                }
                else
                {
                    strFilter = "a.分厂='" + cbxItems_Child.Text.ToString()  + "'";
                }
            }
            else if (strLevel == "工作站")
            {
                if (cbxItems_Child.Text == "全部")
                {
                    strFilter = "a.分厂='" + cbxItems_Father.Text.ToString() + "'";
                }
                else
                {
                    strFilter = "a.分厂='" + cbxItems_Father.Text.ToString() + "' AND a.工作站='" + cbxItems_Child.Text.ToString() + "'";
                }
            }
            return strFilter;
        }

        //按汇总方式进行分析，即显示一段时间综合结果
        private void getSQL_Summrize()
        {
            this.Text = "按" + strLevel + " 统计产量并分析效率( " + strD1 + " - " + strD2 + " )";

            if (rbtnFactory.Checked == true)
            {
                getSQL_Summrize_Factory();
            }          
            else if (rbtnStation.Checked == true)
            {
                getSQL_Summrize_Station();
            }
        }

        private void getSQL_Summrize_Factory()
        {
            strSql = @"SELECT ISNULL(a.分厂,'NULL') AS 分厂,部件数量,ISNULL(工时,0) AS  工时,
                        人工,ISNULL(CAST((工时/人工) AS DECIMAL(18,3)),0) AS 效率
                        FROM
                        (SELECT SUB_FACTORY AS 分厂,
                        CAST(SUM(InsideQty*Part_QTY/Order_QTY) AS DECIMAL(18,1)) AS 部件数量,
                        CAST(SUM(COMB_TIME*InsideQty*Part_QTY/Order_QTY)/3600 AS DECIMAL(18,2)) AS 工时
                        FROM View_OP_Inside_Detail
                        WHERE Scn_Date>='" + strD1 + @"' AND  Scn_Date<='" + strD2 + @"'
                        GROUP BY SUB_FACTORY) AS a
                        LEFT JOIN
                        (SELECT SUB_FACTORY AS 分厂,SUM(WORK_HOURS) AS 人工
                        FROM View_HR_Work_Hours_Actual_Overall
                        WHERE WORK_DATE>='" + strD1 + @"' AND  WORK_DATE<='" + strD2 + @"'
                        GROUP BY SUB_FACTORY) AS b
                        ON a.分厂=b.分厂
                        WHERE " + strFilter;
        }

        private void getSQL_Summrize_Station()
        {
            strSql = @"SELECT ISNULL(a.工作站,'NULL') AS 工作站,部件数量,ISNULL(工时,0) AS 工时,
                                    人工,ISNULL(CAST((工时/人工) AS DECIMAL(18,3)),0) AS 效率
                                    FROM
                                    (SELECT SUB_FACTORY AS 分厂,WORKSTATION AS 工作站,
                                    CAST(SUM(InsideQty*Part_QTY/Order_QTY) AS DECIMAL(18,1)) AS 部件数量,
                                    CAST(SUM(COMB_TIME*InsideQty*Part_QTY/Order_QTY)/3600 AS DECIMAL(18,2)) AS 工时
                                    FROM View_OP_Inside_Detail
                                    WHERE Scn_Date>='" + strD1 + @"' AND  Scn_Date<='" + strD2 + @"'
                                    GROUP BY SUB_FACTORY,WORKSTATION) AS a
                                    LEFT JOIN
                                    (SELECT SUB_FACTORY AS 分厂,WORKSTATION AS 工作站,SUM(WORK_HOURS) AS 人工
                                    FROM View_HR_Work_Hours_Actual_Overall
                                    WHERE WORK_DATE>='" + strD1 + @"' AND  WORK_DATE<='" + strD2 + @"'
                                    GROUP BY SUB_FACTORY,WORKSTATION) AS b
                                    ON a.工作站=b.工作站
                                    WHERE " + strFilter;
        }
           
        //按趋势方式进行分析，即显示一段时间演化趋势
        private void getSQL_Trending()
        {
            if (cbxItems_Child.Text == "")
            {
                MessageBox.Show("请选择具体分析项目！");
                this.Text = "效率与产量";
                return;
            }

            this.Text = cbxItems_Child.SelectedValue.ToString() + " " + strLevel + " 产量统计及效率分析( " + strD1 + " - " + strD2 + " )";

            string strCurItem = cbxItems_Child.Text;

            if (rbtnFactory.Checked == true)
            {
                getSQL_Trending_Factory(strCurItem);
            }
            else if (rbtnStation.Checked == true)
            {
                getSQL_Trending_Station(strCurItem);
            }
        }

        private void getSQL_Trending_Factory(string strCurItem)
        {
            strSql = @"SELECT ISNULL(a.扫描日期,'NULL') AS 扫描日期,部件数量,ISNULL(工时,0) AS  工时,
                        人工,ISNULL(CAST((工时/人工) AS DECIMAL(18,3)),0) AS 效率
                        FROM
                        (SELECT Scn_Date AS 扫描日期,SUB_FACTORY AS 分厂,
                        CAST(SUM(InsideQty*Part_QTY/Order_QTY) AS DECIMAL(18,1)) AS 部件数量,
                        CAST(SUM(COMB_TIME*InsideQty*Part_QTY/Order_QTY)/3600 AS DECIMAL(18,2)) AS 工时
                        FROM View_OP_Inside_Detail
                        WHERE Scn_Date>='" + strD1 + @"' AND  Scn_Date<='" + strD2 + @"'
                        GROUP BY Scn_Date,SUB_FACTORY) AS a
                        LEFT JOIN
                        (SELECT WORK_DATE AS 工作日,SUB_FACTORY AS 分厂,SUM(WORK_HOURS) AS 人工
                        FROM View_HR_Work_Hours_Actual_Overall
                        WHERE WORK_DATE>='" + strD1 + @"' AND  WORK_DATE<='" + strD2 + @"'
                        GROUP BY WORK_DATE,SUB_FACTORY) AS b
                        ON a.扫描日期=b.工作日 AND a.分厂=b.分厂
                        WHERE " + strFilter + @"
                        ORDER BY 扫描日期";
        }

        private void getSQL_Trending_Station(string strCurItem)
        {
            strSql = @"SELECT ISNULL(a.扫描日期,'NULL') AS 扫描日期,部件数量,ISNULL(工时,0) AS 工时,
                        人工,ISNULL(CAST((工时/人工) AS DECIMAL(18,3)),0) AS 效率
                        FROM
                        (SELECT Scn_Date AS 扫描日期,SUB_FACTORY AS 分厂,WORKSTATION AS 工作站,
                        CAST(SUM(InsideQty*Part_QTY/Order_QTY) AS DECIMAL(18,1)) AS 部件数量,
                        CAST(SUM(COMB_TIME*InsideQty*Part_QTY/Order_QTY)/3600 AS DECIMAL(18,2)) AS 工时
                        FROM View_OP_Inside_Detail
                        WHERE Scn_Date>='" + strD1 + @"' AND  Scn_Date<='" + strD2 + @"'
                        GROUP BY Scn_Date,SUB_FACTORY,WORKSTATION) AS a
                        LEFT JOIN
                        (SELECT WORK_DATE AS 工作日,SUB_FACTORY AS 分厂,WORKSTATION AS 工作站,SUM(WORK_HOURS) AS 人工
                        FROM View_HR_Work_Hours_Actual_Overall
                        WHERE WORK_DATE>='" + strD1 + @"' AND  WORK_DATE<='" + strD2 + @"'
                        GROUP BY WORK_DATE,SUB_FACTORY,WORKSTATION) AS b
                        ON a.扫描日期=b.工作日 AND a.工作站=b.工作站
                        WHERE " + strFilter + @"
                        ORDER BY 扫描日期";
        }

        //判断人工工时是否漏维护，即有入仓的日期要有人工工时
        private bool isContinueAferCheckLaborTime(string strD1, string strD2)
        {
            bool bl = false;
            string strSql = @"SELECT Scn_Date AS 扫描日期,a.SUB_FACTORY AS 分厂,入仓工时,WORK_HOURS AS 人工工时
							FROM
							(SELECT Scn_Date,SUB_FACTORY,
							CAST(SUM(COMB_TIME*InsideQty*Part_QTY/Order_QTY)/3600 AS DECIMAL(18,1)) AS 入仓工时
                            FROM View_OP_Inside_Detail
                            WHERE Scn_Date>='" + strD1 + @"' AND  Scn_Date<='" + strD2 + @"'
                            GROUP BY Scn_Date,SUB_FACTORY) AS a
							LEFT JOIN
							(SELECT SUB_FACTORY,WORK_DATE,WORK_HOURS
							FROM View_HR_Work_Hours_Actual_Overall) AS b
							ON a.Scn_Date=b.WORK_DATE AND a.SUB_FACTORY=b.SUB_FACTORY
							WHERE 入仓工时 IS NOT NULL AND WORK_HOURS IS NULL";

            //上面语句中【入仓工时 IS NOT NULL】表示暂【不将漏标准工进作为先决条件】，
            //原因一：补工时涉及多部门，暂做不到及时补齐，且对效率是起拉低作用
            //原因二：分析时，无工时数据会显示出来，用户会感知到，
            //上面语句中【WORKING_HOURS IS NULL】表示【人工工时必须要检查】
            DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
            if (dt.Rows.Count > 0)
            {
                //考虑零星跨天入仓，故可允许用户自主选择是否查看截止当前时间效率分析数据
                if (DevExpress.XtraEditors.XtraMessageBox.Show("当前所选日期段数据中，包含无标准工时产品，或/和漏录入实际人工工时！"
                    + "\r\n" + "因数据维护不完整，现在查看，通常效率偏高！是否查看截止当前时间效率分析数据？"
                    + "\r\n" + "\r\n" + "是：查看基于当前数据的效率分析"
                    + "\r\n" + "否：显示并检查漏维护人工工时数据清单", 
                    "继续进行效率统计分析？", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    bl = true;
                }
                else
                {
                    gridControl1.DataSource = dt;
                    //gridView1.OptionsBehavior.Editable = false;
                    //gridView1.OptionsView.ColumnAutoWidth = true;

                    bl = false;
                }
            }
            else
            {
                bl = true;
            }
            return bl;
        }

        private void setData_GridView(DataTable dt)
        {
            if (dt.Rows.Count > 0)
            {
                gridControl1.DataSource = dt;
                //gridView1.OptionsBehavior.Editable = false;
                //gridView1.OptionsView.ColumnAutoWidth = true;

                //refreshPositionStaduss();
            }
        }

        private void setData_ChartControl(DataTable dt, ChartControl chart, string strFeild_Key, string strFeild_Value)
        {
            chart.Series.Clear();

            if (dt.Rows.Count != 0)
            {
                Series series1 = new Series("", ViewType.Line);

                foreach (DataRow dr in dt.Rows)
                {
                    SeriesPoint p = new SeriesPoint();

                    if (checkBox1.Checked == true)
                    {
                        //因处理不了SYSTEM.DBNull报错，已强制在SQL语句中已将DBNull转换为0
                        //原值显示
                        //防止NULL值报错
                        if (double.Parse(dr["工时"].ToString()) != 0)  //不能用NULL代替空
                        {
                            double[] d = new double[] { double.Parse(Math.Round((decimal.Parse(dr[strFeild_Value].ToString())), 2).ToString()) };
                            p.Values = d;
                            setPointArgument(dr, strFeild_Key, p);
                            series1.Points.Add(p);
                        }
                    }
                    //不过滤消除0值及NULL值
                    else
                    {
                        double[] d = new double[] { double.Parse(Math.Round((decimal.Parse(dr[strFeild_Value].ToString())), 2).ToString()) };
                        p.Values = d;
                        setPointArgument(dr, strFeild_Key, p);
                        series1.Points.Add(p);
                    }
                }

                chart.Series.Add(series1);
                chart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
                Legend Legends = (Legend)chart.Legend;
                Legends.Visibility = DevExpress.Utils.DefaultBoolean.True;
                Legends.AlignmentVertical = LegendAlignmentVertical.Top;
                Legends.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
                Legends.TextVisible = true;

                //强制显示所有x轴标签
                XYDiagram diagram = ((XYDiagram)chart.Diagram);
                diagram.AxisX.QualitativeScaleOptions.AutoGrid = false;
                diagram.AxisX.Label.ResolveOverlappingOptions.AllowHide = false;

                //设置Series的标签
                series1.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;//每个点都显示数据
            }
        }

        //排除因IE_WorkCenter_Definition、OP_MGT_Factory_Workstation、OP_MGT_Workstation_Process三个表中
        //PROCESS_CODE、WORKSTATION未同步定义，导致x轴标签出现NULL值，Argument报错，
        public void setPointArgument(DataRow dr, string strFeild_Key, SeriesPoint p)
        {
            if (dr[strFeild_Key].ToString() == "")
            {
                p.Argument = "NULL";
            }
            else
            {
                p.Argument = dr[strFeild_Key].ToString();
            }
        }

        #region 选项区联动设置-查询条件初始化

        private void rbtnSummarize_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnSummarize.Checked == true)
            {
                //汇总与趋势改为同样层级联动逻辑-2020/6/1
                //doClearViewAndChartData();
                //rbtnFactory.Checked = true;//层级复位

                //cbxItems_Father.Enabled = false;
                //cbxItems_Child.Enabled = false;

                //doResetChildCbx();//重置子项控件

                doConditionDriverLevel();

            }
        }

        private void rbtnTrending_CheckedChanged(object sender, EventArgs e)
        {            
            if (rbtnTrending.Checked == true)
            {
                doConditionDriverLevel();
            }
        }

        private void doConditionDriverLevel()
        {
            doClearViewAndChartData();
            rbtnFactory.Checked = true;//层级复位

            cbxItems_Father.Enabled = false;
            cbxItems_Child.Enabled = true;

            doResetChildCbx();//重置子项控件

            //直接加载子项列表
            SetSubItemDataCollection("1=1", "SUB_FACTORY");
        }

        private void rbtnFactory_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnFactory.Checked == true)
            {
                doClearViewAndChartData();

                cbxItems_Father.Enabled = false;
                cbxItems_Child.Enabled = true;
                    
                doResetChildCbx();

                //直接加载子项列表
                SetSubItemDataCollection("1=1", "SUB_FACTORY");
            }
        }

        private void rbtnStation_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnStation.Checked == true)
            {
                doClearViewAndChartData();

                cbxItems_Father.Enabled = true;
                cbxItems_Child.Enabled = true;
                    
                doResetChildCbx();
            }
        }

        private void cbxItems_Father_TextChanged(object sender, EventArgs e)
        {
            string strCondition = "";
            if (cbxItems_Father.Text.ToString() == "")
            {
                strCondition = "1=1";
            }
            else
            {
                strCondition = "SUB_FACTORY = '" + cbxItems_Father.Text.ToString() + "'";
            }

            //分厂不需要重置处理
            if (rbtnStation.Checked == true)
            {
                SetSubItemDataCollection(strCondition, "WORKSTATION");
            }        
        }

        //加载下拉选项
        private void SetSubItemDataCollection(string strCondition, string strLevel)
        {
            string sql = "";
            sql = @"SELECT DISTINCT " + strLevel + @" FROM View_OP_Resource_Plan
                    WHERE " + strCondition;
            DataTable dt = null;
            dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);

            //下拉选项加载
            ArrayList list = new ArrayList();
            foreach (DataRow dr in dt.Rows)
            {
                list.Add(dr[0].ToString().Trim());
            }

            //仅当选择按汇总方式时才增加
            if (rbtnSummarize.Checked==true)
            {
                list.Add("全部");
            }

            cbxItems_Child.DataSource = list;
            cbxItems_Child.Text = "";
            //cbxSubItem.Text = "全部";
        }

        //重置子项控件
        private void doResetChildCbx()
        {
            cbxItems_Father.Text = "";
            cbxItems_Child.Text = "";

            cbxItems_Child.DataSource = null;
            cbxItems_Child.Items.Clear();
        }

        #endregion

        #region 选项区联动设置-查询时间初始化

        private void rbtnCurWeek_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnCurWeek.Checked == true)
            {
                doClearViewAndChartData();

                DateTime now = DateTime.Now;
                dteStart.DateTime = now.AddDays(-(int)now.DayOfWeek + 1);
                dteEnd.DateTime = now.AddDays(7 - (int)now.DayOfWeek);
            }
        }

        private void rbtnCurMonth_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnCurMonth.Checked == true)
            {
                doClearViewAndChartData();

                DateTime now = DateTime.Now;
                dteStart.DateTime = now.AddDays(-now.Day + 1);
                dteEnd.DateTime = now.AddMonths(1).AddDays(-now.AddMonths(1).Day + 1).AddDays(-1);
            }
        }

        private void rbtnCurSeason_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnCurSeason.Checked == true)
            {
                doClearViewAndChartData();

                DateTime now = DateTime.Now;
                var time = now.AddMonths(0 - ((now.Month - 1) % 3));
                dteStart.DateTime = time.AddDays(-time.Day + 1);
                var time1 = now.AddMonths((3 - ((now.Month - 1) % 3) - 1));
                dteEnd.DateTime = time1.AddMonths(1).AddDays(-time1.AddMonths(1).Day + 1).AddDays(-1);
            }
        }

        private void dteStart_Enter(object sender, EventArgs e)
        {
            rbtnCurWeek.Checked = false;
            rbtnCurMonth.Checked = false;
            rbtnCurSeason.Checked = false;
        }

        private void dteEnd_Enter(object sender, EventArgs e)
        {
            rbtnCurWeek.Checked = false;
            rbtnCurMonth.Checked = false;
            rbtnCurSeason.Checked = false;
        }

        #endregion

        //重置图表
        private void doClearViewAndChartData()
        {
            gridControl1.DataSource = null;
            gridView1.Columns.Clear();
            chartControl1.DataSource = null;
            chartControl1.Series.Clear();
            chartControl2.DataSource = null;
            chartControl2.Series.Clear();

            this.Text = "效率与产量";
        }

        #region 选项区显示/隐藏、表数据导出/打印、表复制设置、表页脚设置、基础配置窗体跳转

        private void 隐藏选项区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelTop.Height = 3;
        }

        private void 显示选项区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelTop.Height = 84;
        }

        private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Lamex.Common.ExecelHelper.GridViewToExcel(gridView1);
        }

        private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Lamex.Common.ExecelHelper.GridViewToPrint(gridControl1, this.Text);
        }

        //gridView仅复制单元格内容，复制选中行焦点单元格的值
        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(gridView1.GetFocusedRowCellValue(gridView1.FocusedColumn));
                e.Handled = true;
            }

            //或设置属性
            //optionBehavior - CopyToClipboardWithColumnHeader = false;
            //optionSelection - MultiSelectMode = CellSelect;
        }

        //表页脚设置
        private void TotalSum()
        {
            if (gridView1.RowCount > 0)
            {
                gridView1.Columns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
                gridView1.Columns[0].SummaryItem.DisplayFormat = "合计：";
                if (gridView1.Columns.Contains(gridView1.Columns["部件数量"]))
                {
                    gridView1.Columns["部件数量"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                    this.gridView1.Columns["部件数量"].SummaryItem.DisplayFormat = "{0:N}";
                    // this.gridView1.Columns["部件数量"].Width = 80;
                }
                if (gridView1.Columns.Contains(gridView1.Columns["工时"]))
                {
                    gridView1.Columns["工时"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                    this.gridView1.Columns["工时"].SummaryItem.DisplayFormat = "{0:N}";
                    //this.gridView1.Columns["工时"].Width = 80;
                }
                if (gridView1.Columns.Contains(gridView1.Columns["人工"]))
                {
                    gridView1.Columns["人工"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
                    this.gridView1.Columns["人工"].SummaryItem.DisplayFormat = "{0:N}";
                    //this.gridView1.Columns["工时"].Width = 80;
                }
            }
        }

        //基础配置窗体跳转
        private void labelGoto_Click(object sender, EventArgs e)
        {
            Loginer.CurrentUser.FunctionId = "menuEFF_Inside_Detail";
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("View_OP_Inside_Detail", 1, false, false), sender as ToolStripMenuItem);
        }

        private void cbxItems_Father_SelectedIndexChanged(object sender, EventArgs e)
        {
            doClearViewAndChartData();
        }

        private void cbxItems_Child_SelectedIndexChanged(object sender, EventArgs e)
        {
            doClearViewAndChartData();
        }

        private void dteStart_EditValueChanged(object sender, EventArgs e)
        {
            doClearViewAndChartData();
        }

        private void dteEnd_EditValueChanged(object sender, EventArgs e)
        {
            doClearViewAndChartData();
        }

        #endregion

        #region 实例化标准功能

        public override void DoView(IButtonInfo sender)
        {
            sbtnView_Click(null, null);
            base.DoView(sender);
        }

        public override void DoExport(IButtonInfo sender)
        {
            导出ToolStripMenuItem_Click(null, null);
            base.DoView(sender);
        }

        public override void DoPrint(IButtonInfo sender)
        {
            打印ToolStripMenuItem_Click(null, null);
            base.DoView(sender);
        }

        #endregion

    }
}